package org.yoyo.classroom.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class PasswordUtils {

    private static final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    /**
     * 对密码进行加密
     * @param rawPassword 原始密码
     * @return 加密后的密码
     */
    public static String encodePassword(String rawPassword) {
        return passwordEncoder.encode(rawPassword);
    }

    /**
     * 验证密码是否匹配
     * @param rawPassword 原始密码
     * @param encodedPassword 加密后的密码
     * @return 如果匹配返回true，否则返回false
     */
    public static boolean matches(String rawPassword, String encodedPassword) {
        return passwordEncoder.matches(rawPassword, encodedPassword);
    }

//    public static void main(String[] args) {
//        String password = "12345678";
//        String encodedPassword = encodePassword(password);
//        System.out.println("Encoded Password: " + encodedPassword);
//
//        boolean isMatch = matches(password, encodedPassword);
//        System.out.println("Password matches: " + isMatch);
//    }
}
